﻿using System.Collections.Generic;
using System.Text;

namespace SimpleOrmCFPC.Core.Query.Where
{
    public class MethodCallWhereElement : IWhereElement
    {
        private IEnumerable<IWhereElement> parameters;
        private string methodName;

        public MethodCallWhereElement(IEnumerable<IWhereElement> parameters, string methodName)
        {
            this.parameters = parameters;
            this.methodName = methodName;
        }

        public void Visit(WhereToSqlBuilder visitor, StringBuilder builder, List<object> parameters)
        {
            builder.Append(methodName + "(");
            bool first = true;
            foreach (IWhereElement parameter in this.parameters)
            {
                if (!first)
                    builder.Append(",");
                first = false;
                parameter.Visit(visitor, builder, parameters);

            }
            builder.Append(")");
        }
    }
}